<?php

namespace Modules\Common\General\Security\Api;


use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Modules\Common\Util\System;

class RequestLogMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        $response = $next($request);
        $user = System::user();
        $userId = $user->id;
        $userName = $user->name ?: $user->zh_name;
        $userMobile = $user->mobile;

        Log::info(sprintf('%s %s %s %s', $request->getClientIp(), $userId, $userName, $userMobile), ['req' => $request->all(), 'res' => $response->getContent()]);
        return $response;
    }

}